package com.project.controller;

import com.project.dto.FactoryDto;
import com.project.entity.Product;
import com.project.service.FactoryRemoteService;
import com.project.service.PreOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "采购入库")
@RequestMapping("/preOrder")
public class PreOrderController {
    @Autowired
    public PreOrderService preOrderService;

    @Autowired
    public FactoryRemoteService factoryRemoteService;

    @ApiOperation(value = "供应商id查询")
    @GetMapping("findById/{id}")
    public List<Product> findById(@PathVariable("id") Integer factoryId){
      return   preOrderService.findById(factoryId);
    }

    @ApiOperation("添加商品")
    @PostMapping("addProduct")
    public String  addProduct( Product product, Integer inNum, Integer userId, Integer factoryId){
        preOrderService.addProduct(product,inNum,userId,factoryId);
        return "ok";
    }

    @ApiOperation(value = "修改商品采购数量")
   @PutMapping("updateByInNum/{factoryId}/{productId}/{inNum}")
    public  String  updateByInNum(@PathVariable("factoryId") Integer factoryId,@PathVariable("productId") Integer productId,@PathVariable("inNum") Integer inNum){
      preOrderService.updateByInNum(factoryId,productId,inNum);
      return "ok";
    }

    @ApiOperation("移除商品")
    @DeleteMapping("delByProduct/{factoryId}/{productId}")
    public  String  delByProduct(@PathVariable("factoryId") Integer factoryId,@PathVariable("productId") Integer productId){
        preOrderService.delByProduct(factoryId,productId);
        return "ok";
    }

    @ApiOperation("远程调用供应商")
    @GetMapping("findByFactory/{id}")
    public FactoryDto findByFactory(@PathVariable("id") Integer id){
        return   factoryRemoteService.findById(id);
    }

}
